home *** CD-ROM | disk | FTP | other *** search
Wrap
'FMA Script Framework Plugin 'Winamp 'This plugin controls WinAmp 'TODO: '-Extend Seek dialogue (see carpediem, keep up to date with the tracks current position) Const WINAMP_SEARCH_ARTIST_MATCH = 0 Const WINAMP_SEARCH_ARTIST_SUBSTR = 1 Const WINAMP_SEARCH_TITLE_MATCH = 2 Const WINAMP_SEARCH_TITLE_SUBSTR = 3 Const WINAMP_SEARCH_BOTH_MATCH = 4 Const WINAMP_SEARCH_BOTH_SUBSTR = 5 Const WINAMP_SEARCH_ONE_MATCH = 6 Const WINAMP_SEARCH_ONE_SUBSTR = 7 Class Winamp Private m_Self Private mainMenu Private playListMenu Private searchMenu Public playlistExplorer 'Some info about the plugin Public Property Get SHOWABLE 'Do I have a menu? SHOWABLE = True End Property Public Property Get TITLE 'What's my name? TITLE = "WinAmp" End Property Public Property Get DESCRIPTION 'What's my purpose? DESCRIPTION = "This plugin controls winamp. You may use the menu and the phones volume keys." End Property Public Property Get AUTHOR 'Who created me? AUTHOR = "dVrVm (also starring streawkceur)" End Property Public Property Get URL 'Were can I be found? Where can you get more information? URL = "http://fma.xinium.com/" End Property 'Who am I? Public Property Let Self (s) m_Self = s ' Some init stuff here: If IsEmpty(Settings(Me, "Title")) or Settings(Me, "Title") = "" Then Settings(Me, "Title") = "Winamp" If IsEmpty(Settings(Me, "Exe")) or Settings(Me, "Exe") = "" Then Settings(Me, "Exe") = "C:\Program Files\Winamp\winamp.exe" If IsEmpty(Settings(Me, "PlaylistFolder")) or Settings(Me, "PlaylistFolder") = "" Then Settings(Me, "PlaylistFolder") = Fso.GetParentFolderName(Settings(Me, "Exe")) Set mainMenu = New ManagedMenu Set playListMenu = New ManagedMenu Set searchMenu = New ManagedMenu 'Init searchMenu Dim llist, bi Set llist = New LinkedList bi = llist.BackInserter bi.Item = Array("Browse Artists", m_Self & ".BrowseArtist") bi.Item = Array("Search Artists", m_Self & ".SearchArtist") bi.Item = Array("Search Titles", m_Self & ".SearchTitle") bi.Item = Array("Search Both", m_Self & ".SearchBoth") searchMenu.SetList llist searchMenu.Title = "Search/Browse" End Property Public Property Get Self Self = m_Self End Property 'Display me. Eventually put a menu on the screen Sub Show() 'Set the PathExe, launch the program If Fso.FileExists(Settings(Me, "Exe")) Then ActiveXManager("WinampCOMLib.WinampCOMObj").PathExe = Fso.GetParentFolderName(Settings(Me, "Exe")) Else Debug.ErrorMsg m_Self & " - Init: File not found: " & Settings(Me, "Exe") End If Dim llist, bi, state Set llist = New LinkedList bi = llist.BackInserter If ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = True Then state = ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongState If state = "Playing" Then bi.Item = Array("Restart", Self & ".Play") Else bi.Item = Array("Play", Self & ".Play") End If If state = "Paused" Then bi.Item = Array("Resume", Self & ".Pause") Else bi.Item = Array("Pause", Self & ".Pause") End If bi.Item = Array("Stop", Self & ".Stopp") bi.Item = Array("<< Prev Track ", Self & ".PrevTrack") bi.Item = Array(">> Next Track ", Self & ".NextTrack") bi.Item = Array("Volume", Self & ".Volume") bi.Item = Array("Show Playlist", Self & ".Playlist") bi.Item = Array("Load Playlist", Self & ".LoadPlaylist") bi.Item = Array("Search/Browse", Self & ".SearchBrowse") ' bi.Item = Array("Seek", Self & ".Seek") If ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle Then bi.Item = Array("Shuffle Off", Self & ".Shuffle") Else bi.Item = Array("Shuffle On", Self & ".Shuffle") End If If ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat Then bi.Item = Array("Repeat Off", Self & ".Repeat") Else bi.Item = Array("Repeat On", Self & ".Repeat") End If bi.Item = Array("Help", Self & ".Help") bi.Item = Array("Close", Self & ".Close") Else bi.Item = Array("Launch", Self & ".Launch") End If mainMenu.SetList llist mainMenu.Title = TITLE mainMenu.ShowMenu EventManager.RegisterEvent "MenuClose", Self & ".ExitMenu", Me EventManager.RegisterEvent "ConnectionLost", Self & ".ExitMenu", Me End Sub Sub Launch If Fso.FileExists(Settings(Me, "Exe")) Then ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = True 'Shell.Exec Settings(Me, "Exe") 'Util.WaitForAppLoad Settings(Me, "Title"), 10000 'Give winamp max. 10 secs to load Else Debug.ErrorMsg Self & " - Launch: File not found: " & Settings(Me, "Exe") End If Show End Sub Sub Close ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = False Show End Sub Sub Play ActiveXManager("WinampCOMLib.WinampCOMObj").Play Show End Sub Sub Pause ActiveXManager("WinampCOMLib.WinampCOMObj").Pause Show End Sub Sub Stopp ActiveXManager("WinampCOMLib.WinampCOMObj").Stop Show End Sub Sub PrevTrack ActiveXManager("WinampCOMLib.WinampCOMObj").PreviousTrack Show End Sub Sub NextTrack ActiveXManager("WinampCOMLib.WinampCOMObj").NextTrack Show End Sub Sub Shuffle ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle = Not ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle Show End Sub Sub Repeat ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat = Not ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat Show End Sub Sub VolUp ActiveXManager("WinampCOMLib.WinampCOMObj").Volumeup End Sub Sub VolDn ActiveXManager("WinampCOMLib.WinampCOMObj").VolumeDown End Sub Sub VolUpPress fma.AddTimer 60, Self & ".VolUp" End Sub Sub VolUpRelease fma.DeleteTimer Self & ".VolUp" End Sub Sub VolDnPress fma.AddTimer 60, Self & ".VolDn" End Sub Sub VolDnRelease fma.DeleteTimer Self & ".VolDn" End Sub Sub Volume() EmptyMenu.ShowMenu am.Back = Self & ".VolumeQuit" 'Mangage the menu quit by ourselves 'Volume Up KeyManager.RegisterKey KEY_VOLUP, Self & ".VolUpPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_JOYUP, Self & ".VolUpPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_JOYRIGHT, Self & ".VolUpPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_VOLUP, Self & ".VolUpRelease", STATE_RELEASE, Me KeyManager.RegisterKey KEY_JOYUP, Self & ".VolUpRelease", STATE_RELEASE, Me KeyManager.RegisterKey KEY_JOYRIGHT, Self & ".VolUpRelease", STATE_RELEASE, Me 'Volume Down KeyManager.RegisterKey KEY_VOLDOWN, Self & ".VolDnPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_JOYDOWN, Self & ".VolDnPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_JOYLEFT, Self & ".VolDnPress", STATE_PRESS, Me KeyManager.RegisterKey KEY_VOLDOWN, Self & ".VolDnRelease", STATE_RELEASE, Me KeyManager.RegisterKey KEY_JOYDOWN, Self & ".VolDnRelease", STATE_RELEASE, Me KeyManager.RegisterKey KEY_JOYLEFT, Self & ".VolDnRelease", STATE_RELEASE, Me am.DlgMsgBox "Increase Volume: Joy-up,-right,Vol-up - Decrease volume: Joy-down,-left,Vol-down", 0 End Sub Sub VolumeQuit() KeyManager.DeregisterAll Me MenuStack.Top.Quit 'Remove emtpy menu End Sub Sub ExitMenu ( sName ) If sName = TITLE Then KeyManager.DeregisterAll Me EventManager.DeregisterAll Me End If End Sub Sub Help() EmptyMenu.ShowMenu am.DlgMsgBox "The menu should be mostly self-explaining. Note that you can set Winamp's volume with your phones volume keys!", 0 End Sub Sub Playlist () Dim pList, pLbi, cnt, pageAndIndex 'Retrieve playlist ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList Set pList = New LinkedList pLbi = pList.BackInserter For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListLength - 1 pLbi.Item = Array( getSong(cnt), Self & ".PlaySongShowPlaylist " & cnt) Next If pList.Count < 1 Then pLbi.Item = Array( "(empty)", "am.Update" ) playListMenu.Title = "Playlist" playListMenu.SetList pList pageAndIndex = playListMenu.GetPageAndIndexByItemIndex(ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListPosition - 1) playListMenu.ShowPage(pageAndIndex(0)) 'Show page of currently played song am.Selected = pageAndIndex(1) + 1 'jump to song am.Update End Sub 'Play song and show playlist again Sub PlaySongShowPlaylist( i ) ActiveXManager("WinampCOMLib.WinampCOMObj").PlaySongByPosition(i) Playlist End Sub 'Play song and show the search result again Sub PlaySongShowSearch( i ) ActiveXManager("WinampCOMLib.WinampCOMObj").PlaySongByPosition(i) am.Update End Sub Private Function getSong(p) Dim s, artist, title, mark artist = Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetArtistbyPosition(p)) title = Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongTitlebyPosition(p)) If artist <> "" And title <> "" Then s = artist & " - " & title Else s = artist & title End If s = Replace(s,"( ","(") s = Replace(s," )",")") s = Replace(s,"[ ","[") s = Replace(s," ]","]") If (ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListPosition - 1 = p) Then 'if P is current song being played mark = ">" 'mark song Else mark = " " End If getSong = mark & s End Function Sub LoadPlaylist() If PluginManager.IsClassImported("FileExplorer") Then 'Create a new FileExplorer and browse the playlist folder from the settings Set playlistExplorer = Util.CreateObject("FileExplorer", Self & ".playlistExplorer") playlistExplorer.ShowDir Settings(Me, "PlaylistFolder"), 0 Else Debug.ErrorMsg Self & "You will need the FileExplorer plugin to select playlists!" End If End Sub Sub SearchBrowse() searchMenu.ShowMenu End Sub Sub Seek() EmptyMenu.ShowMenu ActiveXManager("WinampCOMLib.WinampCOMObj").SongPosParseTime = FALSE ActiveXManager("WinampCOMLib.WinampCOMObj").SetLengthParseTime = FALSE am.DlgPercent "Seek", Self & ".SeekResult", 10, 10 * (ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongPosition / ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongLength / 1000) End Sub Sub SeekResult( value, final ) If final = 1 Then ActiveXManager("WinampCOMLib.WinampCOMObj").JumpToTime value * (ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongLength / 10) MenuStack.Top.Quit 'Remove emtpy menu End If End Sub Sub BrowseArtist() Dim llist, bi, cnt, tempMenu 'Retrieve playlist ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList Set llist = New LinkedList bi = llist.BackInserter For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetTotalUniqueArtist - 1 bi.Item = Array(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetUniqueArtist(cnt)), Self & ".BrowseTracksByArtistAndTitle " & WINAMP_SEARCH_ARTIST_MATCH & ", """ & Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetUniqueArtist(cnt)) & """, Empty") Next If llist.Count < 1 Then bi.Item = Array( "(empty)", "am.Update" ) Set tempMenu = New ManagedMenu tempMenu.Title = "Artists" tempMenu.SetList llist tempMenu.ShowMenu End Sub Sub SearchArtist() EmptyMenu.ShowMenu am.DlgInputStr "Search artists", "Artists:", 16, "", Self & ".SearchArtistResult" End Sub Sub SearchArtistResult( input ) MenuStack.Pop 'Remove emtpy menu BrowseTracksByArtistAndTitle WINAMP_SEARCH_ARTIST_SUBSTR, input, "" End Sub Sub SearchTitle() EmptyMenu.ShowMenu am.DlgInputStr "Search titles", "Titles:", 16, "", Self & ".SearchTitleResult" End Sub Sub SearchTitleResult( input ) MenuStack.Pop 'Remove emtpy menu BrowseTracksByArtistAndTitle WINAMP_SEARCH_TITLE_SUBSTR, "", input End Sub Sub SearchBoth() EmptyMenu.ShowMenu am.DlgInputStr "Search both", "Artists/Titles:", 16, "", Self & ".SearchBothResult" End Sub Sub SearchBothResult( input ) MenuStack.Pop 'Remove emtpy menu BrowseTracksByArtistAndTitle WINAMP_SEARCH_ONE_SUBSTR, input, input End Sub Sub BrowseTracksByArtistAndTitle( searchType, a, t ) a = LCase(Trim(a)) t = LCase(Trim(t)) Dim llist, bi, cnt, artist, title, tempMenu, match 'Retrieve playlist ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList Set llist = New LinkedList bi = llist.BackInserter For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListLength - 1 artist = LCase(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetArtistbyPosition(cnt))) title = LCase(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongTitlebyPosition(cnt))) match = False Select Case searchType Case WINAMP_SEARCH_ARTIST_MATCH If artist = a Then match = True Case WINAMP_SEARCH_ARTIST_SUBSTR If InStr(artist, a) > 0 Then match = True Case WINAMP_SEARCH_TITLE_MATCH If title = t Then match = True Case WINAMP_SEARCH_TITLE_SUBSTR If InStr(title, t) > 0 Then match = True Case WINAMP_SEARCH_BOTH_MATCH If artist = a And title = t Then match = True Case WINAMP_SEARCH_BOTH_SUBSTR If InStr(artist, a) > 0 And InStr(title, t) > 0 Then match = True Case WINAMP_SEARCH_ONE_MATCH If artist = a Or title = t Then match = True Case WINAMP_SEARCH_ONE_SUBSTR If InStr(artist, a) > 0 Or InStr(title, t) > 0 Then match = True End Select If match Then bi.Item = Array( getSong(cnt), Self & ".PlaySongShowSearch " & cnt ) Next If llist.Count < 1 Then bi.Item = Array( "(No matches!)", "am.Update" ) Set tempMenu = New ManagedMenu tempMenu.SetList llist tempMenu.ShowMenu End Sub End Class